/**
 * @author 黄波
 * 创建日期：2011Oct 7, 2011
 * TODO// N/A
 */
package com.platform.res.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.platform.pojo.ResInfo;
import com.platform.res.bo.ResBo;

/**
 * 更新资源信息类型
 */
public class UpdateResInfoTypeAction extends ResourceSupport {

	private String resId;	//资源ID
	private String type;	//类型ID
	public String getResId() {
		return resId;
	}
	public void setResId(String resId) {
		this.resId = resId;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	@Override
	public String execute() throws Exception {
		if(type == null || type.equals("") || type.equals("0")) {
			//未修改
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setCharacterEncoding("utf-8");
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.flush();
			out.write("<script>alert('未填写类别！');history.back();</script>");
			out.close();
			return null;
		} else {
			ResBo bo = ResBo.getInstance();
				ResInfo item = bo.getInfo(resId);
				item.setTypeId(Integer.parseInt(type));
			if(bo.updateInfo(item)) {
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setCharacterEncoding("utf-8");
				response.setContentType("text/html");
				PrintWriter out = response.getWriter();
				out.flush();
				out.write("<script>alert('修改成功！');history.back();</script>");
				out.close();
				return null;
			} else {
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setCharacterEncoding("utf-8");
				response.setContentType("text/html");
				PrintWriter out = response.getWriter();
				out.flush();
				out.write("<script>alert('修改失败，内部服务器错误！');history.back();</script>");
				out.close();
				return null;
			}
		}
	}
	
}
